<template>
  <div class="order-info-container">
    <div class="order-header">
      <h1>订单查询</h1>
    </div>
    <div class="order-input">
      <label for="orderNumber">订单编号:</label>
      <input type="text" id="orderNumber" v-model="orderNumber" placeholder="请输入订单编号" />
      <button @click="fetchOrderInfo">查询</button>
    </div>
    <div v-if="orderFetched" class="order-details">
      <GoodsInfo :goodInfo="goodInfo"></GoodsInfo>
      <LogisticsItem :logisticsInfo="logisticsInfo" :logisticsStatus="logisticsStatus"
        :logisticsCompany="logisticsCompany" :logisticsNo="logisticsNo">
      </LogisticsItem>
    </div>
    <div v-if="showDialog" class="loading-message">正在加载订单信息...</div>
  </div>
</template>

<script>
import GoodsInfo from '../components/GoodsInfo'
import LogisticsItem from '../components/LogisticsItem'
import { orderInfo } from '../models/data.js'
export default {
  data() {
    return {
      orderFetched: false,
      showDialog: false,
      orderData: null,
      logisticsInfo: null,
      goodInfo: null,
      orderNumber: null,
      logisticsStatus: null, // 状态
      logisticsCompany: null, // 快递公司
      logisticsNo: null // 快递运单号

    };
  },
  components: {
    GoodsInfo,
    LogisticsItem
  },
  methods: {
    fetchOrderInfo() {
      this.showDialog = true
      setTimeout(() => {
        this.orderFetched = true;
        this.orderData = orderInfo
        this.goodInfo = this.orderData['goodInfo']
        this.logisticsInfo = this.orderData['logisticsInfo']
        this.orderNumber = this.orderData.orderNumber
        this.logisticsStatus = this.orderData.logisticsStatus
        this.logisticsCompany = this.orderData.logisticsCompany
        this.logisticsNo = this.orderData.logisticsNo

        this.showDialog = false
      }, 1000);
    },
    viewShippingDetails() {
      window.open(this.trackingUrl, '_blank');
    }
  }
};
</script>

<style scoped>
.order-info-container {
  font-family: Arial, sans-serif;
  background-color: #f4f4f9;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  max-width: 600px;
  margin: 20px auto;
}

.order-header {
  text-align: center;
  margin-bottom: 20px;
}

.order-header h1 {
  color: #333;
  font-size: 24px;
  margin: 0;
}

.order-input {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  margin-bottom: 20px;
}

.order-input label {
  font-size: 16px;
  margin-bottom: 5px;
  width: 130px;
  font-size: 20px;
  line-height: 40px;
  margin-right: 10px;
}

.order-input input {
  padding: 10px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 4px;
  margin-bottom: 10px;
  width: calc(100% - 22px);
  /* Subtract padding and border */
}

.order-input button {
  padding: 10px;
  font-size: 16px;
  border: none;
  border-radius: 4px;
  background-color: #007bff;
  color: white;
  cursor: pointer;
  width: 90px;
  margin-left: 10px;
}

.order-input button:hover {
  background-color: #0056b3;
}

.loading-message {
  text-align: center;
  font-size: 16px;
  color: #6c757d;
}
</style>